<template>
	<view class="">
		<j-cell-group>
		    <j-cell title="人形检测"  :more="false">
				<view slot="tips">
					<!-- <switch :checked="humanDetect" color="#FF0025" style="transform:scale(0.8)" @change="humanDetectSwitchChange"></switch> -->
					<j-switch  v-model="humanDetect" color="#FF0025" @change="humanDetectSwitchChange" ></j-switch>
				</view>
			</j-cell>
			<j-cell title="显示智能踪迹" :more="false">
				<view slot="tips">
					<switch :checked="smartTrack" color="#FF0025"  @change="smartTrackSwitchChange"></switch>
				</view>
			</j-cell>
		</j-cell-group>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				device:{},
				humanDetect:false,
				smartTrack:false,
				humanDetectQuery:{},
				smartTrackQuery:{},
				trackQuery:{},//移动追踪
				isTrackDetect:false,
				
			}
		},
		onLoad(opt) {
			let enData = decodeURIComponent(opt.device)
			this.device = JSON.parse(enData)
			// this.device = JSON.parse(opt.device)
			let data = { Name: 'Detect.HumanDetection' };
			this.getConfig(data)
			let constant = getApp().globalData.constant;
			if(this.device.parentPid == constant.DEVICE_TYPE.EE_DEV_BOUTIQUEROBOT){
				let data2 = { Name: 'Detect.DetectTrack' };
				this.getConfig(data2)
			}
		},
		methods:{
			//人形检测
			humanDetectSwitchChange(e){
				this.humanDetectQuery['Detect.HumanDetection'][0].Enable = e
				
				if(e&&this.isTrackDetect){
					uni.showModal({
						content:'人形检测和移动追踪不能同时打开，如果开启人形检测，移动追踪将会被关闭,确认操作？',
						success: (res) => {
							if(res.confirm){
								this.humanDetect = true 
								this.trackQuery['Detect.DetectTrack'].Enable = false
								this.setConfig(this.humanDetectQuery)
								this.setConfig(this.trackQuery)
							}else{
								this.humanDetect = false
							}
						}
					})
				}else{
					this.setConfig(this.humanDetectQuery)
				}
			},
			// 智能踪迹
			smartTrackSwitchChange(e){
				this.humanDetectQuery['Detect.HumanDetection'][0].ShowTrack = e.detail.value
				this.setConfig(this.humanDetectQuery)
			},
			// 获取配置
			getConfig(data){
				let token = this.device.token;
				getApp().globalData.api.getconfig(data, token, (result) => {
					console.log('获取配置',result);
					if(result.Name == 'Detect.HumanDetection'){
						this.humanDetectQuery = result
						this.humanDetect = this.humanDetectQuery['Detect.HumanDetection'][0].Enable
						this.smartTrack = this.humanDetectQuery['Detect.HumanDetection'][0].ShowTrack
					}
					if(result.Name == 'Detect.DetectTrack'){
						this.trackQuery = result
						this.isTrackDetect = this.trackQuery['Detect.DetectTrack'].Enable
					}
				    
				});
			},
			// 设置配置
			setConfig(data){
				let token = this.device.token;
				getApp().globalData.api.setconfig(data, token, (result) => {
					console.log('设置配置',result);
				});
				
			}
			
		}
	}
</script>

<style>
</style>